package com.ll.method;

/**
 * @author 刘龙
 * @version 1.0
 */
public class ThreadMethodExercise {
    public static void main(String[] args) throws InterruptedException {
        MyDemoThread myDemoThread = new MyDemoThread();
        // 如果我们希望当主线程结束后,子线程可以自动退出
        // 只需将子线程设为守护线程
        myDemoThread.setDaemon(true);

        myDemoThread.start();

        for (int i = 0; i < 10; i++) {
            System.out.println("主线程执行中");
            Thread.sleep(500);

        }
    }
}

class MyDemoThread extends Thread {
    @Override
    public void run() {
        for (; ; ) {
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("子线程继续执行...");
        }
    }
}
